//
//  LNViewController.m
//  LNBeeHive
//
//  Created by wwww on 2019/9/30.
//  Copyright © 2019 淘发现1iOS. All rights reserved.
//

#import "LNViewController.h"

@interface LNViewController ()

@property (nonatomic,readwrite,strong) LNViewModel *viewModel;

@property(nonatomic,strong,readwrite) UIPercentDrivenInteractiveTransition *interactivePopTransition;
@end

@implementation LNViewController

-(void)dealloc{
    
    self.viewModel = nil;
//    SKDealloc;
    NSLog(@"%@控制器销毁",self.title);
}

+(instancetype)allocWithZone:(struct _NSZone *)zone{
    
    LNViewController *viewController = [super allocWithZone:zone];
    @weakify(viewController)
    [[viewController
      rac_signalForSelector:@selector(viewDidLoad)]
     subscribeNext:^(id x) {
         @strongify(viewController)
         [viewController bindViewModel];
     }];
    return viewController;
}

- (instancetype)initWithViewModel:(LNViewModel *)viewModel {
    self = [super init];
    if (self) {
        self.viewModel = viewModel;
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (@available(iOS 11.0, *)) {
        self.automaticallyAdjustsScrollViewInsets = YES;
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    self.view.backgroundColor = [UIColor whiteColor];
    self.view.autoresizesSubviews = NO;
}

// 绑定数据
- (void)bindViewModel{
    // 导航标题
//    RAC(self.navigationItem , title) = RACObserve(self, viewModel.title);
    // 绑定错误信息
    [self.viewModel.errors subscribeNext:^(NSError *error) {
        /// 这里可以统一处理某个错误，例如用户授权失效的的操作
        NSLog(@"...错误...");
    }];
}

#pragma mark - Orientation
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {return UIInterfaceOrientationMaskPortrait;}
- (BOOL)shouldAutorotate {return YES;}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {return UIInterfaceOrientationPortrait;}
@end
